using System;
using UnityEditor;
using UnityEngine;

namespace HuaXianQu.ProtoBuffEx.ToolEditor
{
    public class ProtoPopupWin : EditorWindow
    {
        Vector2 scrollPos = Vector2.zero;
        string titleStr, messageStr, okStr;

        public static void DisplayDialog(string title, string message, string ok)
        {
            ProtoPopupWin win = GetWindow<ProtoPopupWin>(title);

            win._DisplayDialog(title, message, ok);
            //win.maxSize = new Vector2(800,600);
        }

        private void _DisplayDialog(string title, string message, string ok)
        {
            titleContent = new GUIContent(title);
            titleStr = title;
            messageStr = message;
            okStr = ok;
        }

       

        public void OnGUI()
        {
            // 开始垂直布局
            EditorGUILayout.BeginVertical();
            {
                // 开始滚动视图
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandHeight(true));
                {
                    // 使用 GUIStyle 设置自动换行
                    GUIStyle labelStyle = new GUIStyle(EditorStyles.label);
                    labelStyle.wordWrap = true; // 启用自动换行
                    labelStyle.richText = true; // 启用富文本
                    // 显示文本，并适应窗口宽度
                    GUILayout.Label(messageStr, labelStyle, GUILayout.ExpandWidth(true));
                }
                EditorGUILayout.EndScrollView();

                // 开始水平布局（用于按钮）
                EditorGUILayout.BeginHorizontal();
                {
                    GUILayout.FlexibleSpace(); // 左侧弹性空间
                    if (GUILayout.Button(okStr, GUILayout.Width(100)))
                    {
                        Close(); // 关闭窗口
                    }
                    GUILayout.FlexibleSpace(); // 右侧弹性空间
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();
        }
        
    }
}